package 字符串;

/**
 * @author mubei
 * @date 2021/12/14
 * @description
 */
public class Demo04 {


    public static void main(String[] args) {
        compressString();
    }
    public static String compressString() {
        String s = "aabcccccaa";
        StringBuilder sb = new StringBuilder();
        char[] chars = s.toCharArray();

        int l=0,r=1;
        for (; r < chars.length; r++) {
            if(chars[l] != chars[r]){
                sb.append(chars[l]);
                l=r;
            }
                r++;

        }
        return  sb.toString().length() >= s.length() ?   s : sb.toString();


    }
}
